package real.evaluation.set;

import real.evaluation.Evaluator;
import real.evaluation.Formula;
import real.evaluation.RealEvaluationException;
import real.evaluation.RealSetConstruction;
import real.evaluation.SyntacticalConstruction;
import real.lang.RealLangException;
import real.lang.RealObject;
import real.lang.RealSet;
import real.utils.RealEventArgs;
import real.utils.RealEventHandler;

public class ConstrainedSetConstruction extends RealSetConstruction {

	public ConstrainedSetConstruction(String symbol, Formula phi)
	{
		this.constrainedSymbol = symbol;
		this.formula = phi; 
	}
	
	
	private String constrainedSymbol;	

	/**
	 * @param constrainedSymbol the constrainedSymbol to set
	 */
	public void setConstrainedSymbol(String constrainedSymbol) {
		this.constrainedSymbol = constrainedSymbol;
	}

	/**
	 * @return the constrainedSymbol
	 */
	public String getConstrainedSymbol() {
		return constrainedSymbol;
	}

	private Formula formula;
	

	/**
	 * @param formula the formula to set
	 */
	public void setFormula(Formula formula) {
		this.formula = formula;
	}

	/**
	 * @return the formula
	 */
	public Formula getFormula() {
		return formula;
	}
	
	public class FormulaEvaluationBeginHandler implements RealEventHandler 
	{
		ConstrainedSetConstruction constraited;
		
		public void perfomAction(RealEventArgs e) throws RealEvaluationException {
			if (!e.containsKey(Evaluator.CONSTR_VAR_NAME))
				throw new RealEvaluationException("EventArgs does not pass contruction variable");
			SyntacticalConstruction<? extends RealObject> construction = (SyntacticalConstruction<? extends RealObject>) e.get(Evaluator.CONSTR_VAR_NAME);
			if (construction instanceof Formula)
			{
				//constraited.
			}
		}		
		
		public FormulaEvaluationBeginHandler(ConstrainedSetConstruction constrained) {
			this.constraited = constrained;
		}
	}
	
	FormulaEvaluationBeginHandler beginFormula = new FormulaEvaluationBeginHandler(this);
	
	@Override
	public RealSet ProperEvaluate(Evaluator eval)
	throws RealLangException {
		eval.OnConstructionEvaluationBegin.addHandler(this.beginFormula);
		// TODO eval
		eval.OnConstructionEvaluationBegin.removeHandler(this.beginFormula);
		return null;
	}
}
